<template>
  <el-dialog :title="$t('BusinessConfig.letterReview.limit')" :visible.sync="showState" :before-close="handleClose" :close-on-click-modal="false">
    <el-form ref="formValidate" :model="formValidate" :rules="rules" label-width="150px" class="demo-ruleForm">
      <el-form-item :label="$t('BusinessConfig.letterReview.number')" prop="count">
        <el-input-number
          v-model="formValidate.count"
          style="width: 100%"
          :min="0"
          :step="1"
          step-strictly
          :max="100000000000"
          controls-position="right"
          :placeholder="$t('BusinessConfig.letterReview.prompt.number')"
        />
      </el-form-item>
      <el-row style="text-align: center">
        {{ $t('BusinessConfig.letterReview.tip') }}
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleClose">{{ $t('common.operate.cancel') }}</el-button>
      <el-button type="primary" :loading="submitLoading" @click="handleSubmit">{{ $t('BusinessConfig.machineReview.submit') }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { updateCreditContent } from '@/api/risk'
export default {
  name: 'LetterReviewDialog',
  props: {
    showDialog: {
      type: Boolean,
      default: false
    },
    chooseItem: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  data() {
    return {
      submitLoading: false,
      formValidate: {
        count: null,
        id: null
      },
      rules: {
        count: [{ required: true, type: 'number', message: this.$t('BusinessConfig.letterReview.number') + this.$t('common.null'), trigger: 'blur' }]
      }
    }
  },
  computed: {
    showState: {
      get: function() {
        return this.showDialog
      },
      set: function() {
      }
    }
  },
  mounted() {
    this.formValidate = this.chooseItem
  },
  methods: {
    handleClose() {
      this.$emit('change-dialog', false)
      this.$refs['formValidate'].clearValidate()
    },
    handleSubmit() {
      updateCreditContent(this.formValidate)
        .then(res => {
          this.submitLoading = false
          if (res.success) {
            this.$message.success(this.$t('common.tips.operateSuccess'))
            this.$emit('edit-success')
            this.handleClose()
          } else {
            this.$message.error(res.message)
          }
        })
        .catch(err => {
          this.$message.error(err.message)
          this.submitLoading = false
        })
    }
  }
}
</script>

<style scoped>

</style>
